import './../sass/login&register.scss';

const $ = require('jquery');

$("#register_btn").on('click', function () {
    const isPhone = false;
    const regPhone = /^[1][3][0-9]{9}$/;
    if (regPhone.test($("#regPhone").val())) {
        $.ajax({
            url: '/students/register',
            data: {
                name: $("#regname").val(),
                phone: $("#regPhone").val(),
                password: $("#regpass").val(),
            },
            type: 'post',
            success({message,code}) {
                alert(message);
            }
        })
    } else {
        msg()
    }
})

$("#login_btn").on('click', function () {
    const isPhone = false;
    const regPhone = /^[1][3][0-9]{9}$/;
    if (regPhone.test($("#loginPhone").val())) {
        $.ajax({
            url: '/students/login',
            data: {
                phone: $("#loginPhone").val(),
                password: $("#loginpass").val(),
            },
            type: 'post',
            success({message,code,token}) {
                if (code == '200') {
                    alert(message);
                    localStorage.token = token;
                    location.assign('./../html/index.html');
                }else{
                    alert(message)
                }
            }
        })
    } else {
        msg()
    }
})


function msg() {
    $("#msg").fadeIn(300);
    const timer = setTimeout(() => {
        clearTimeout(timer);
        $("#msg").fadeOut(1000);
    }, 1000);
}
// $("#regname")
// $("#regPhone")
// $("#regpass")